package com.example.wanbaqian.activity;

import android.Manifest;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.example.wanbaqian.R;
import com.example.wanbaqian.base.BaseActivity;
import com.example.wanbaqian.config.CommonValue;
import com.example.wanbaqian.utils.BaseUtils;
import com.tencent.bugly.beta.Beta;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by pengfei on 2017/8/11 0011.
 * 添加修改
 * description：<p>关于我们</p>
 */
public class AboutUsActivity extends BaseActivity implements BaseActivity.PermissionListeren {

    @BindView(R.id.txt_abouttitle)
    TextView mTitle;
    @BindView(R.id.txt_phone)
    TextView mPhone;
    @BindView(R.id.txt_version1)
    TextView mVersion1;
    @BindView(R.id.txt_version2)
    TextView mVersion2;
    private Dialog mDialog;
    private boolean isCall = true;

    @Override
    protected int getLayout() {
        return R.layout.activity_aboutus;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setStatusBarColor(R.color.main_color);
        setTitle();
    }

    @OnClick({R.id.rel_versions, R.id.img_aboutback, R.id.rel_phone})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_aboutback:
                finish();
                break;
            case R.id.rel_phone:
                requestPermission(CommonValue.REQUEST_CODE1, this, Manifest.permission.CALL_PHONE);
                break;
            case R.id.rel_versions:
                Beta.checkUpgrade();
                break;
        }
    }

    private void setTitle() {
        mTitle.setText("关于我们");
        mVersion1.setText(""+getResources().getString(R.string.app_version) + BaseUtils.geVersionCode(mContext));
        mVersion2.setText("V" + BaseUtils.geVersionCode(mContext));
    }

    /**
     * 客服
     */
    private void Callphone() {
        String tel = mPhone.getText().toString();
        Intent inter = new Intent();
        inter.setAction(Intent.ACTION_CALL);
        inter.setData(Uri.parse("tel:" + tel));
        startActivity(inter);
    }

    @Override
    protected void initDate() {
    }

    private void setCall() {
        mDialog = new Dialog(mContext, R.style.dialogstyle);
        View view_cate = LayoutInflater.from(this).inflate(R.layout.dialog_call, null);
        mDialog.setContentView(view_cate);
        //获取当前Activity所在的窗体
        Window dialogWindow = mDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        //获得窗体的属性
        mDialog.setCancelable(true);
        mDialog.setCanceledOnTouchOutside(true);
        TextView txt = (TextView) view_cate.findViewById(R.id.txt_cancel);
        TextView txt_true = (TextView) view_cate.findViewById(R.id.txt_true);
        txt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
            }
        });

        txt_true.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Callphone();
                mDialog.dismiss();
            }
        });
        mDialog.show();
    }

    @Override
    public void onGranted(int requestCode) {
        setCall();
    }

    @Override
    public void onDenied(int requestCode, List<String> deniedPermissions, List<String> noReminderPermissions) {
        showToast("请同意通话权限");
    }
}
